﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <% 
    int totalPage = (int)ViewData["totalPage"];
    int currentPage = (int)ViewData["currentPage"];
    %>
    <div style="text-align:center;margin-top:20px;margin-bottom:20px;width:800px">
    <%if (currentPage > 1)
      { 
    %>
        <a style="margin-left:5px;margin-right:5px" href="javascript:void(0);" onclick="gotoPage(1);">首页</a>
        <a style="margin-left:5px;margin-right:5px" href="javascript:void(0);" onclick="gotoPage(<%=(currentPage - 1) %>);">前一页</a>
    <%}
      else
      {
    %>
        <span style="margin-left:5px;margin-right:5px">首页</span>
        <span style="margin-left:5px;margin-right:5px">前一页</span>
    <%
      }
        if (currentPage - 5 > 1)
        {
    %>
        <span style="margin-left:5px;margin-right:5px">...</span>
    <%
        for (int i = 5; i >= 1; i--)
        {
    %>
       <a  style="margin-left:5px;margin-right:5px;font-weight:bold;" href="javascript:void(0);" onclick="gotoPage(<%=(currentPage - i) %>);"><%=(currentPage - i)%></a>
    <%
        }
        }
        else
        {
            for (int i = 1; i < currentPage; i++)
            {
    %>
        <a style="margin-left:5px;margin-right:5px;font-weight:bold;" href="javascript:void(0);" onclick="gotoPage(<%=i %>);"><%=i%></a>
    <%
            }
        }
    %>
        <span style="margin-left:5px;margin-right:5px;font-weight:bold;"><%=currentPage %></span>
    <%if (currentPage + 5 < totalPage)
      {
        for (int i = 1; i <= 5; i++)
        {
    %>
       <a style="margin-left:5px;margin-right:5px;font-weight:bold;" href="javascript:void(0);" onclick="gotoPage(<%=(currentPage + i) %>);"><%=(currentPage + i)%></a>
    <%
        }
    %>
        <span style="margin-left:5px;margin-right:5px">...</span>
    <%
        }
        else
        {
            for (int i = 1; i <= totalPage - currentPage; i++)
            {
    %>
        <a style="margin-left:5px;margin-right:5px;font-weight:bold;" href="javascript:void(0);" onclick="gotoPage(<%=(currentPage + i) %>);"><%=(currentPage + i)%></a>
    <%
            }
        }
    %>
    <%if (currentPage < totalPage)
      { 
    %>
        
        <a style="margin-left:5px;margin-right:5px" href="javascript:void(0);" onclick="gotoPage(<%=(currentPage + 1) %>);">后一页</a>
        <a style="margin-left:5px;margin-right:5px" href="javascript:void(0);" onclick="gotoPage(<%=totalPage %>);">末页</a>
    <%}
      else
      {
    %>
        <span style="margin-left:5px;margin-right:5px">后一页</span>
        <span style="margin-left:5px;margin-right:5px">末页</span>
    <%
      } 
    %>
    </div>

    <script type="text/javascript" language="javascript">
        function gotoPage(pageNo) {
            document.getElementById("PageNo").value = pageNo;
            $("form")[0].submit();
        }
    </script>